<template>
	<div>
		<el-dialog :title="title" :close-on-click-modal="false" v-dialogDrag :visible.sync="visible">
			<el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading"
				:class="method==='view'?'readonly':''" :disabled="method==='view'" label-width="120px">
				<el-row :gutter="15">
					<el-col :span="12">
						<el-form-item label="签到时间一" prop="sigino" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.sigino" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签退时间一" prop="sigouto" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.sigouto" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签到时间二" prop="sigint" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.sigint" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签退时间二" prop="sigoutt" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.sigoutt" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签到时间三" prop="signinth" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.signinth" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签退时间三" prop="signoutth" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.signoutth" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签到时间四" prop="signinf" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.signinf" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="签退时间四" prop="signoutf" :rules="[
                 ]">
							<el-date-picker style="width: 100%;" v-model="inputForm.signoutf" type="datetime"
								value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择日期时间">
							</el-date-picker>
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="公司id" prop="company.id" :rules="[
                 ]">
							<SelectTree ref="company" :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }" url="/sys/office/treeData?type=2" :value="inputForm.company.id" :clearable="true"
								:accordion="true" @getValue="(value) => {inputForm.company.id=value}" />
						</el-form-item>
					</el-col>
					<el-col :span="12">
						<el-form-item label="备注信息" prop="remarks" :rules="[
                 ]">
							<el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<span slot="footer" class="dialog-footer">
				<el-button size="small" @click="visible = false">关闭</el-button>
				<el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定
				</el-button>
			</span>
		</el-dialog>
	</div>
</template>

<script>
	import SelectTree from '@/components/treeSelect/treeSelect.vue'
	export default {
		data() {
			return {
				title: '',
				method: '',
				visible: false,
				loading: false,
				inputForm: {
					id: '',
					sigino: '',
					sigouto: '',
					sigint: '',
					sigoutt: '',
					signinth: '',
					signoutth: '',
					signinf: '',
					signoutf: '',
					company: {
						id: ''
					},
					remarks: ''
				}
			}
		},
		components: {
			SelectTree
		},
		methods: {
			init(method, id) {
				this.method = method
				this.inputForm.id = id
				if (method === 'add') {
					this.title = `新建打卡设置表`
				} else if (method === 'edit') {
					this.title = '修改打卡设置表'
				} else if (method === 'view') {
					this.title = '查看打卡设置表'
				}
				this.visible = true
				this.loading = false
				this.$nextTick(() => {
					this.$refs.inputForm.resetFields()
					if (method === 'edit' || method === 'view') { // 修改或者查看
						this.loading = true
						this.$http({
							url: `/sys/syschicksetting/syschickensetting/queryById?id=${this.inputForm.id}`,
							method: 'get'
						}).then(({
							data
						}) => {
							this.inputForm = this.recover(this.inputForm, data.syschickensetting)
							this.loading = false
						})
					}
				})
			},
			// 表单提交
			doSubmit() {
				this.$refs['inputForm'].validate((valid) => {
					if (valid) {
						this.loading = true
						this.$http({
							url: `/attendance/syschicksetting/sysChickSetting/save`,
							method: 'post',
							data: this.inputForm
						}).then(({
							data
						}) => {
							this.loading = false
							if (data && data.success) {
								this.visible = false
								this.$message.success(data.msg)
								this.$emit('refreshDataList')
							}
						})
					}
				})
			}
		}
	}
</script>
